/**
 * 项目名：phms3
 * 日期：    2019-11-22 16:35:44
 * Copyright (c) 2015- HTSC-版权所有
 */

package com.joysuch.wwyt.core.repository;

import com.joysuch.wwyt.core.entity.BaseRoleUserLoginRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * BaseBizCodeSeedDao
 *
 */
public interface BaseRoleUserLoginRoleDao extends JpaRepository<BaseRoleUserLoginRole, Long> {

    @Modifying
    @Transactional
    @Query("delete from BaseRoleUserLoginRole m where m.userId=?1 and m.roleId in (?2)")
    public void deleteByIds(Long userId, List<Long> ids);

    @Transactional
    public void deleteByUserId(Long userId);

    @Query("select distinct(m.roleId) from BaseRoleUserLoginRole m where m.userId=?1")
    public List<Long> selectRoleIdsByUserId(Long userId);

    @Query("select m.userId from BaseRoleUserLoginRole m where m.roleId=?1 and m.userId in (?2)")
    public List<Long> findByRoleUserIds(Long roleId, List<Long> userIds);

    @Transactional
    public void deleteByRoleId(Long userId);

    @Query("select m.userId from BaseRoleUserLoginRole m where m.roleId in ?1")
    List<Long> findUserIdByRoleUserIds(List<Long> roleIds);

    @Query("select m.userId from BaseRoleUserLoginRole m where m.roleId = ?1")
    List<Long> findUserIdByRoleUserId(Long roleId);
}
